package com.mtnz.njk.Controller;

import com.mtnz.njk.Service.CouponManagerService;
import com.mtnz.njk.entity.CouponTypeEntity;
import com.mtnz.njk.result.ResponseMessage;
import com.mtnz.njk.result.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: app管理代金券控制层
 * @Author: FBL
 * @CreateDate: 2019\8\23 0023 17:59
 * @Version: 1.0
 */
@RestController
@RequestMapping("/coupon")
@CrossOrigin
public class CouponManagerController {

    @Autowired
    CouponManagerService couponManagerService;

    /**
     * 代金券列表
     *
     * @param key
     * @param pageNum
     * @param pageSize
     * @return
     * @throws Exception
     */
    @PostMapping("/listCouponType")
    public ResponseResult listCouponType(String key, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) throws Exception {
        return couponManagerService.listCouponType(key, pageNum, pageSize);
    }

    /**
     * 编辑代金券
     *
     * @param couponTypeEntity
     * @return
     * @throws Exception
     */
    @PostMapping("/updateCouponType")
    public ResponseResult updateCoupon(@RequestBody CouponTypeEntity couponTypeEntity) throws Exception {
        if (couponTypeEntity == null)
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return couponManagerService.updateCoupon(couponTypeEntity);
    }

    /**
     * 新增代金券
     *
     * @param couponTypeEntity
     * @return
     * @throws Exception
     */
    @PostMapping("/insertCouponType")
    public ResponseResult insertCouponType(@RequestBody CouponTypeEntity couponTypeEntity) throws Exception {
        if (couponTypeEntity == null)
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return  couponManagerService.insertCouponType(couponTypeEntity);
    }
}
